package com.hzy.yiyaoba.bean;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hzy.yiyaoba.utils.Config;
import com.hzy.yiyaoba.utils.Config.LoreConfig;
import com.lidroid.xutils.http.RequestParams;

//{"success": true,
//"yi18":
// {
//   "title":"告别双下巴和颈部赘肉",
//   "message":" ……",
//   "count":0,
//   "author":"yi18",
//   "loreclass":11,
//   "className":"减肥瘦身",
//   "time":"Dec 5, 2013 12:00:00 AM",
//   "id":1
//   }
//}

public class LoreShow {
	private String title;
	private String message;
	private int count;
	private String author;
	private int loreClass;
	private String className;
	private String time;
	private int id;

	public LoreShow(String title, String message, int count, String author, int loreClass, String className, String time, int id) {
		this.title = title;
		this.message = message;
		this.count = count;
		this.author = author;
		this.loreClass = loreClass;
		this.className = className;
		this.time = time;
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public int getLoreClass() {
		return loreClass;
	}

	public void setLoreClass(int loreClass) {
		this.loreClass = loreClass;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public static RequestParams createRequestParams(int id) {
		RequestParams params = new RequestParams();
		params.addBodyParameter(LoreConfig.KEY_ID, String.valueOf(id));
		return params;
	}

	public static LoreShow parseLoreShow(String json) throws Exception {
		JSONObject obj = JSON.parseObject(json);
		if (!obj.getBoolean(Config.JSON_SUCCESS)) {
			return null;
		}
		JSONObject showObj = obj.getJSONObject(Config.JSON_CONTENT);
		int id = showObj.getInteger(LoreConfig.JSON_ID);
		String title = showObj.getString(LoreConfig.JSON_TITLE);
		String message = showObj.getString(LoreConfig.JSON_MESSAGE);
		int count = showObj.getInteger(LoreConfig.JSON_COUNT);
		String author = showObj.getString(LoreConfig.JSON_AUTHOR);
		int loreClass = showObj.getInteger(LoreConfig.JSON_LORE_CLASS);
		String className = showObj.getString(LoreConfig.JSON_CLASS_NAME);
		String time = showObj.getString(LoreConfig.JSON_TIME);
		return new LoreShow(title, message, count, author, loreClass, className, time, id);
	}

}
